// 配置分页插件的目录
layui.extend({
    customPage: '../lib/customPage/custom-page',
    apiconfig: '../public/apiconfig'
});
layui.use(['form',"table","laypage","customPage","laydate"], function () {
    var $ = layui.jquery
        form = layui.form,
        table = layui.table,
        laypage = layui.laypage,
        laydate = layui.laydate,
        customPage = layui.customPage //自定义分页插件
        element = layui.element;
        var mainTop=$(".main_top").outerHeight()
        $(".tableMb").height(window.screen.height-(230+mainTop+10));
        workSheet(form,'conferenceRoom',"conference_room");
        workSheet(form,'conferenceLevel',"conference_level");
        $.ajaxSetup({ cache: false })
        var searchstr={
            // userId:sessionStorage.getItem("userid")
        }
        customPageFun(searchstr,'gt/opm/conference/admin/page')
        table.render({
            elem: '#tabList'
            ,title: '用户表'
            ,toolbar: '<div><a class="layui-btn layui-btn-radius" lay-event="today" id="today">今天</a><button type="button" class="layui-btn layui-btn-radius"  lay-event="tomorrow" id="tomorrow">明天</button><button type="button" class="layui-btn layui-btn-radius"  lay-event="TheWeek" id="TheWeek">本周</button></div>'
            ,defaultToolbar: []
            // ,page: true //开启分页
            ,cols: [
                [{ type: 'checkbox', title: '选择',  width: 30},
                { type: 'numbers', title: '序号',  width: 40},
                {field: 'conferenceName',title: '会议名称',align:"center"}, 
                {field: 'conferenceRoom', title: '会议室',align:"center" }, 
                {field: 'conferenceLevel', title: '会议级别',align:"center" }, 
                {field: 'conferenceDate', width:330, title: '会议时间',align:"center",templet:function(d){
                    var list='';
                    if(d.conferenceDate.length!=1){
                        list='<p class="hoverImg"></p>';
                        for(var o=0;o<d.conferenceDate.length;o++){
                            list += '<p style="width:300px;text-align: center">'+d.conferenceDate[o]["startDate"]+'-'+d.conferenceDate[o]["endDate"]+'</p>  '
                        }
                    }else{
                        for(var o=0;o<d.conferenceDate.length;o++){
                            list += '<p style="width:300px;text-align: center">'+d.conferenceDate[o]["startDate"]+'-'+d.conferenceDate[o]["endDate"]+'</p>  '
                        }
                    }
                    return list;
                } }, 
                {field: 'conferenceDebugDate', title: '联调时间',align:"center", width:330 , templet:function(d){
                    var list='';
                    if(d.conferenceDebugDate.length!=1){
                        list='<p class="hoverImg"></p>';
                        for(var o=0;o<d.conferenceDebugDate.length;o++){
                            list += '<p style="width:300px;text-align: center">'+d.conferenceDebugDate[o]["startDate"]+'-'+d.conferenceDebugDate[o]["endDate"]+'</p>  '
                        }
                    }else{
                        for(var o=0;o<d.conferenceDebugDate.length;o++){
                            list += '<p style="width:300px;text-align: center">'+d.conferenceDebugDate[o]["startDate"]+'-'+d.conferenceDebugDate[o]["endDate"]+'</p>  '
                        }
                    }
                    return list;
                } }, 
                {field: 'username',align:"center", title: '详情', width: 80,templet:function(){
                   return '<a class="layui-btn layui-btn-xs"  data-title="查看会议" lay-event="LisyJobsLook">查看</a>'
                }}
                ]
            ],
            done: function(data) {
            }
        }); 
         //执行示例 如何采用 table.reload 方法分页的渲染放到 table之后
        function customPageFun(searchstr,url){
            customPage.render({
                elem: '#page',
                layout: ['skipFirst', 'prev', 'skip', 'next', 'skipLast', 'count'],
                url: url,
                method: 'GET',
                request: {
                    pageName: 'pageNum',
                    limitName: 'pageSize'
                },
                where: {
                    userId:searchstr.userId,
                    conferenceName:searchstr.conferenceName,
                    conferenceRoom:searchstr.conferenceRoom,
                    conferenceLevel:searchstr.conferenceLevel,
                    conferenceStartDate:searchstr.conferenceStartDate,
                    conferenceEndDate:searchstr.conferenceEndDate,
                    conferenceDebugStartDate:searchstr.conferenceDebugStartDate,
                    conferenceDebugEndDate:searchstr.conferenceDebugEndDate,
                    dateRangeType:searchstr.dateRangeType
                },
                parseData:function(res){
                    return {
                        "code":res.code, //解析接口状态
                        "flag":res.flag, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "data": res.data.rows, //解析数据列表
                        "total":res.data.total
                    };
                },
                done: function(res, curr, data) {
                    if(res.flag==true){
                        table.reload('tabList', {
                            data: res.data,
                            limit: res.size
                        });
                    }else{
                        layer.alert(res.msg)
                    }
                    
                }
            });
        }
   
        //日期范围
        laydate.render({
            elem: '#conferenceDate'
            ,range: true
        });
         //日期范围
         laydate.render({
            elem: '#conferenceDebugDate'
            ,range: true
        });
    // 监听列表点击事件
        table.on('tool(tabList)', function(obj){
            if(obj.event=="LisyJobsLook"){
                window.parent.xadmin.add_tab('会议详情','views/MeetingApplicationDetail.html','',obj.data.id)
            }
        })
        table.on('toolbar(tabList)', function(obj){
          if(obj.event=="today"){
                searchstr.dateRangeType='01';
            }else if(obj.event=="tomorrow"){
                searchstr.dateRangeType='02'; 
            }else if(obj.event=="TheWeek"){
                searchstr.dateRangeType='03';
               
            }
            customPageFun(searchstr,'gt/opm/conference/admin/page/range');
        })
        var active={
            search:function(){
                var conferenceDate=$("#conferenceDate").val(),conferenceDebugDate=$("#conferenceDebugDate").val();
                var conferenceDatestartTime=conferenceDate.substr(0,10),
                conferenceDateendTime=conferenceDate.substr(13,conferenceDate.length),
                conferenceDebugDatestartTime=conferenceDebugDate.substr(0,10),
                conferenceDebugDateendTime=conferenceDebugDate.substr(13,conferenceDebugDate.length);

                searchstr.conferenceName=$("#conferenceName").val();
                searchstr.conferenceRoom=$("#conferenceRoom option:selected").val();
                searchstr.conferenceLevel=$("#conferenceLevel option:selected").val();
                searchstr.workSheetCode=$("#workSheetCode").val();
                searchstr.conferenceStartDate=conferenceDatestartTime;
                searchstr.conferenceEndDate=conferenceDateendTime;
                searchstr.conferenceDebugStartDate=conferenceDebugDatestartTime;
                searchstr.conferenceDebugEndDate=conferenceDebugDateendTime;
                delete searchstr.dateRangeType;
                customPageFun(searchstr,'gt/opm/conference/admin/page')
            }
        }
        $(".bao_loginbtn").on('click',function(data){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        })
})